package com.qfjy.service.impl;

import com.qfjy.entity.po.MeetingGrab;
import com.qfjy.mapper.MeetingGrabMapper;
import com.qfjy.service.MeetingGrabService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.UUID;
@Transactional
@Service
@Slf4j
public class MeetingGrabServiceImpl implements MeetingGrabService {
    @Autowired
    private MeetingGrabMapper meetingGrabMapper;

    @Override
    public int insertSelective(MeetingGrab record) {
        record.setId(UUID.randomUUID().toString());
        record.setCreateDate(new Date());

        // status 表的公共字段 （0无效，1有效）
        record.setGrabStatus(1);
        // grab_status 匹配状态（0未审批 1匹配成功 2匹配失败）
        record.setGrabStatus(0);
        // grab_data 匹配时间


        return meetingGrabMapper.insertSelective(record);
    }

    @Override
    public List<MeetingGrab> selectListMeetingGrabByUid(int uid) {
        return meetingGrabMapper.selectListMeetingGrabByUid(uid);
    }

    @Override
    public int updateMeetingGrabChoose(String pid, int uid) {

        int num = meetingGrabMapper.updateMeetingGrabGrabStatusFail(pid);
        if (num<1){
            throw new RuntimeException("就选你功能失败");
        }
        int num1 = meetingGrabMapper.updateMeetingGrabGrabStatusSuccess(pid, uid);
        if (num1<1){
            throw new RuntimeException("就选你功能成功时失败");
        }
        return 1;
    }
}
